package com.red.controller.admin;

import com.red.dto.HomePageQueryDTO;
import com.red.dto.TravelNotesDTO;
import com.red.dto.commentPageQueryDTO;
import com.red.entity.TravelNotes;
import com.red.result.PageResult;
import com.red.result.Result;
import com.red.service.TravelNotesService;
import com.red.vo.CommentAllVO;
import io.swagger.annotations.ApiModelProperty;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("AdminTraveNotes")
@RequestMapping("/admin/travelNote")
@Slf4j
@CrossOrigin
public class TravelNotesController {

    @Autowired
    private TravelNotesService travelNotesService;

    /**
     * 分页查询
     * @param dto
     * @return
     */
    @GetMapping("/notesPort")
    @ApiModelProperty("分页查询")
    public Result<PageResult> notesPort(TravelNotesDTO dto){
        log.info("分页查询信息：{}",dto);
        PageResult pageResult = travelNotesService.adminPageQuery(dto);
        return Result.success(pageResult);
    }

    /**
     * 审批
     * @param travelNotes
     * @return
     */
    @PostMapping
    public Result approval(@RequestBody TravelNotes travelNotes){
        log.info("状态审批{}",travelNotes);
        travelNotesService.approval(travelNotes);
        return Result.success();
    }

    /**
     * 分页查询所有评论
     * @return
     */
    @GetMapping("/commentPageQuery")
    public Result<PageResult> commentPageQuery(commentPageQueryDTO dto){
        log.info("dto = {}",dto);
        PageResult pageResult = travelNotesService.commentPageQuery(dto);
        return Result.success(pageResult);
    }

    /**
     * 根据评论Id删除评论
     * @param ids
     * @return
     */
    @DeleteMapping("/comment/{ids}")
    public Result deleteComment(@PathVariable List<Long> ids){
        log.info("删除的评论Id = {}", ids);
        travelNotesService.deleteCommentByIds(ids);
        return Result.success();
    }
}
